package com.yege.uilt;

import org.apache.hadoop.hbase.io.ByteArrayOutputStream;

import java.io.IOException;
import java.io.ObjectOutputStream;

public class ByteUtil {
    /**
     * 将Object对象转byte数组
     */
    public static byte[] toByte(Object obj) {
        byte[] bytes = null;
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        try {
            ObjectOutputStream oos = new ObjectOutputStream(bos);
            oos.writeObject(obj);
            oos.flush();
            bytes = bos.toByteArray();
            oos.close();
            bos.close();
        }catch (IOException ex) {
            ex.printStackTrace();
        }
        return bytes;
    }
}
